<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>新增门店分组</title>
		<link rel="stylesheet" href="../../../css/base.css" />
		<link rel="stylesheet" href="../../../css/common.css" />
		<link rel="stylesheet" type="text/css" href="store.css">
		<!-- Bootstrap Core CSS -->
		<link href="../../../sbadmin/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- MetisMenu CSS -->
		<link href="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
		<!-- DataTables CSS -->
		<link href="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
		<!-- Custom CSS -->
		<link href="../../../sbadmin/dist/css/sb-admin-2.css" rel="stylesheet">
		<!-- Custom Fonts -->
		<link href="../../../sbadmin/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	</head>

	<body style="background:#fff;">
		<div class="container-fluid" style="background-color: #fff;">
			<div class="title">
				门店分组 > 新增门店分组
			</div>
			<div class="zl-ccbox">
				<div class="zl-cccc pr">
					<div class="edit-item clb">
						<div class="edit-item-tt fl"><em>*</em>分组名：</div>
						<div class="edit-item-cc fl ml10">
							<input type="text" class="edit-input" id="typeName" />
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl">包含门店：</div>
						<div class="edit-item-cc fl ml10">
							<div class="clb" id="addListA">
								<!--<div class="asdList">门店1</div>-->
							</div>
							<div class="asctBox">
								城市选择：
								<select class="eic-select" style="width: 100px;" id="ctName"></select>
							</div>
							<div class="asctList">
								<ul class="asctLi clb">

								</ul>
							</div>
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl">是否启用：</div>
						<div class="edit-item-cc fl ml10">
							<select class="eic-select" style="width: 200px;" id="isY">
								<option value="1">是</option>
								<option value="0">否</option>
							</select>
						</div>
					</div>
					<div class="edit-item clb">
						<div class="edit-item-tt fl"></div>
						<div class="edit-item-cc fl ml10">
							<a href="personalMsg.html" class="fl commqx-btn">取消</a>
							<a href="javascript:void(0)" class="fl commqr-btn ml15" id="addPer">确定</a>
						</div>
					</div>
				</div>
			</div>

			<!-- jQuery -->
			<script src="../../../sbadmin/bower_components/jquery/dist/jquery.min.js"></script>
			<!-- Bootstrap Core JavaScript -->
			<script src="../../../sbadmin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
			<!-- Metis Menu Plugin JavaScript -->
			<script src="../../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.js"></script>
			<!-- DataTables JavaScript -->
			<script src="../../../sbadmin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
			<script src="../../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
			<!-- Custom Theme JavaScript -->
			<script src="../../..//sbadmin/dist/js/sb-admin-2.js"></script>
			<!-- Page-Level Demo Scripts - Tables - Use for reference -->
			<script src="../../../js/layer/layer.js"></script>
			<script type="text/javascript" src="../../../js/common.js"></script>
			<script type="text/javascript" src="../../../js/jquery-ui.min.js"></script>
			<script src="store.js"></script>
	</body>
	<script>
		$.ajax({
			url: "https://order.wz1996.wang/wzbg/openedcity/all",
			type: 'get',
			contentType: 'application/json',
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			},
			success: function(data) {
				console.log(data);
				//登录状态
				var html = "";
				if(data.code == "1") {
					html += "<option>--请选择--</option>"
					for(var i = 0; i < data.data.length; i++) {
						html += "<option id=" + data.data[i].cityId + " value=" + data.data[i].cityId + ">" + data.data[i].cityName + "</option>"
					}
					$("#ctName").html(html);
				} else if(data.code == "-1") {
					layar(data.msg);
					setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
				} else {
					layar(data.msg);
				}
			},
			error: function(e) {
				errcode(e);
			}
		});

		$("#ctName").change(function() {
			var id = $("#ctName option:selected").html();
			var user = {
				"store": {
					"cityName": id
				}
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/store/query",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(user),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data)
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<li id=" + data.data[i].store.id + ">" + data.data[i].store.name + "</li>"
						}
						$(".asctLi").html(html)

					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}
				},
				error: function(e) {
					errcode(e);
				}
			});

		});

		$(".asctLi").on("click", "li", function() {
			var hascur = $(this).hasClass("cur");
			var sid = $(this).attr("id");
			var html = $(this).html();
			if(hascur) {
				$(this).removeClass("cur");
				$("#addListA div").each(function(i) {
					var sdid = $("#addListA div").eq(i).attr("id");
					if(sid == sdid) {
						$("#addListA div").eq(i).remove();
					}
				})
			} else {
				$(this).addClass("cur");
				var apdhtml = "<div class='asdList' id=" + sid + ">" + html + "</div>";
				$("#addListA").append(apdhtml);
			}

		})

		//点上面下面没掉
		$("#addListA").on("click", "div", function() {
			nsid = "";
			var sid = $(this).attr("id");
			var sthis = $(this);
			sthis.remove();
			$(".asctLi li").each(function(i) {
				var sdid = $(".asctLi li").eq(i).attr("id");
				if(sid == sdid) {
					$(".asctLi li").eq(i).removeClass("cur");
					sthis.remove();
				}
			})
		})
		var allref = [];
		$("#addPer").on('click', function() {
			allref = [];
			$(".asdList").each(function(index) {
				var ids = {};
				ids['id'] = $(this).attr("id");
				ids['name'] = $(this).html();
				allref.push(ids);
			});
			var typeName = $("#typeName").val();
			var isY = $("#isY option:selected").val();

			var post_data = {
				"storeGroup": {
					"name": typeName,
					"status": isY
				},
				"stores": allref
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/storegroup/add",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(post_data),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data)
					if(data.code == "1") {
						layar("添加成功！");
						setTimeout("window.location.href='store.html'", 1000);
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}
				},
				error: function(e) {
					errcode(e);
				}
			});

		})
	</script>

</html>